﻿using SuperX.Common.Collection;
using SuperX.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperX.DataService;

namespace SuperX.DeviceService.Template
{
    public class TemplateConfig : BasicObjCollection<IBasicObject>
    {
        public TemplateConfig()
        {
            this.Name = "Template";
        }

        private ObjectCollection<TemplateConfig, TemplateDriverConfig> _templateItem;

        public ObjectCollection<TemplateConfig, TemplateDriverConfig> TemplateItem
        {
            get => _templateItem ?? (_templateItem = new ObjectCollection<TemplateConfig, TemplateDriverConfig>(this));
            set
            {
                _templateItem = value;
                _templateItem.SetParent(this);
            }
        }

        #region IBasicObject

        public override IBasicObject this[string name] => TemplateItem[name];

        public override List<string> GetKeys()
        {
            return TemplateItem.Keys.ToList();
        }

        public override List<IBasicObject> GetValues()
        {
            var group = TemplateItem.Values.OfType<IBasicObject>().ToList();
            return group;
        }

        public override bool IsUniqueName(string name, IObjCollection parent)
        {
            if (parent != null)
            {
                return parent.IsUniqueName(name, null);
            }

            return TemplateItem[name] == null;
        }

        #endregion IBasicObject
    }
}